﻿Imports System.Data.OleDb

Public Class DanhMucKhachHang
    Public Sub Them(ByVal MaKhachHang As String, ByVal CodeKhachHang As String, ByVal TenKhachHang As String, ByVal SoDT As String, ByVal Fax As String, ByVal DiaChi As String, ByVal MaTinhThanh As Integer, ByVal MaSoThue As String, ByVal TaiKhoan As String, ByVal NganHang As String, ByVal TenTinhThanh As String, ByVal GhiChu As String, ByVal NhanVienTiepThiId As Integer, ByVal TenNhanVienTiepThi As String)
        Try
            Dim dataAccess As New DataAccess
            Dim dbConn As New OleDb.OleDbConnection
            Dim dbCommand As OleDbCommand
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            Dim query As String = ""
            query = String.Format("Insert Into DanhMucKhachHang(MaKhachHang,CodeKhachHang,TenKhachHang,SoDienThoai,Fax,DiaChi,MaTinhThanh,MaSoThue,SoTaiKhoan,NganHang,TenTinhThanh,GhiChu,NhanVienTiepThiId,TenNhanVienTiepThi) Values(N'{0}',N'{1}',N'{2}',N'{3}',N'{4}',N'{5}',{6},N'{7}',N'{8}',N'{9}',N'{10}',N'{11}',{12},N'{13}')", MaKhachHang, CodeKhachHang, TenKhachHang, SoDT, Fax, DiaChi, MaTinhThanh, MaSoThue, TaiKhoan, NganHang, TenTinhThanh, GhiChu, NhanVienTiepThiId, TenNhanVienTiepThi)
            dbCommand = New OleDbCommand(query, dbConn)
            dbCommand.ExecuteNonQuery()
            dbConn.Close()
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
    Public Sub ChinhSua(ByVal KhachHangId As Integer, ByVal CodeKhachHang As String, ByVal TenKhachHang As String, ByVal SoDT As String, ByVal Fax As String, ByVal DiaChi As String, ByVal MaTinhThanh As Integer, ByVal MaSoThue As String, ByVal TaiKhoan As String, ByVal NganHang As String, ByVal TenTinhThanh As String, ByVal GhiChu As String, ByVal NhanVienTiepThiId As Integer, ByVal TenNhanVienTiepThi As String)
        Try
            Dim dataAccess As New DataAccess
            Dim dbConn As New OleDb.OleDbConnection
            Dim dbCommand As OleDbCommand
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            Dim query As String = ""
            query = String.Format("Update DanhMucKhachHang Set CodeKhachHang=N'{0}',TenKhachHang=N'{1}',SoDienThoai=N'{2}',Fax=N'{3}',DiaChi=N'{4}',MaTinhThanh={5},MaSoThue=N'{6}',SoTaiKhoan=N'{7}',NganHang=N'{8}',TenTinhThanh=N'{9}',GhiChu=N'{10}',NhanVienTiepThiId={11},TenNhanVienTiepThi=N'{12}',NgaySuaGanNhat=N'{13}',NguoiSuaGanNhat=N'{14}' Where KhachHangId={15}", CodeKhachHang, TenKhachHang, SoDT, Fax, DiaChi, MaTinhThanh, MaSoThue, TaiKhoan, NganHang, TenTinhThanh, GhiChu, NhanVienTiepThiId, TenNhanVienTiepThi, NgayTao, NguoiTao, KhachHangId)
            dbCommand = New OleDbCommand(query, dbConn)
            dbCommand.ExecuteNonQuery()
            dbConn.Close()
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
    Public Function Xoa(ByVal KhachHangId As Integer, ByVal ValueRecord As String) As Boolean
        Try
            Dim dlgRes As DialogResult
            dlgRes = MessageBox.Show( _
                  "Bạn muốn xóa  : " & ValueRecord, _
                  "Thông báo", _
            MessageBoxButtons.OKCancel, _
                  MessageBoxIcon.Warning)
            If dlgRes = DialogResult.OK Then
                Dim dataAccess As New DataAccess
                Dim dbConn As New OleDb.OleDbConnection
                Dim dbCommand As OleDbCommand
                dataAccess.ConnectDatabase_DBAccess(dbConn)
                Dim query As String = "Update DanhMucKhachHang Set Xoa=1,NgayXoa='" & NgayTao() & "',NguoiXoa='" & NguoiTao() & "'  Where KhachHangId=" & KhachHangId
                dbCommand = New OleDbCommand(query, dbConn)
                dbCommand.ExecuteNonQuery()
                dbConn.Close()
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            ShowError()
        End Try
    End Function
End Class
